home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / comm_io.zip / COMM_IO.ASM next >
Assembly Source File  |  1986-12-09  |  22KB  |  612 lines

  1.                                 page,132
  2. ;-------------------------------------------------------------------------------
  3. ;                         ----  COMM_IO.ASM  ----
  4. ; To use it just MODE your COM1: to whatever speed you like, I've only tested
  5. ; it to 9600 baud it does'nt use DOS calls so its pretty fast I dont know
  6. ; how it will effect non IBM hardware, works just fine on PC'S Limited 286-8.
  7. ; It may not be fully debugged, I have'nt tested the XON or XOFF functions
  8. ; Simple communications work fine, It ignores the modem control line so to use
  9. ; it you must provide software handshaking for a terminal that does'nt have a
  10. ; buffer.
  11. ; The recieving buffer is 512 bytes so as long as you dont let it fillup you
  12. ; wont loose any characters, of coarse you could make it as larger if necessary.
  13. ;
  14. ;
  15. ; Filename: COMM_IO
  16. ; Program.: Clipper Communication for Com1:
  17. ; Authors.: Curt Klinsing,Modifed by Patrick Jonte
  18. ; Date....: April 20, 1986
  19. ;
  20. ; Function: A set of Clipper W85 callable functions to support
  21. ;           interrupt driven character I/O on the  IBM PC. Input
  22. ;           is buffered, output is polled.
  23. ;
  24. ;
  25. ;
  26. ; 1- OUTP_CHAR {call} outputs a character string up to first null encountered.
  27. ;    (Note- all clipper strings are terminated by a ascii null or hex 00)
  28. ;    Example:
  29. ;             PUTCHARS='a character string '
  30. ;             CALL OUTP_CHAR WITH PUTCHARS
  31. ;
  32. ; 2- INP_CHAR(.T.or.F.) {function} returns a character string of the characters
  33. ;    available in the input buffer (maximum of 512 characters)
  34. ;    and gives the option of deleting characters read from input buffer .T. or
  35. ;    .F. leaving it untouched which allows easy monitoring for a special
  36. ;    character(s)
  37. ;    Example:
  38. ;             RECV_STR=INP_CHAR(.T.)  & reads buffer and kills characters read
  39. ;                                       from buffer
  40. ;
  41. ; 3- INP_CNT() {function} returns numeric indicating the number of characters
  42. ;    that the input buffer is holding (Maximum of 512).
  43. ;    Example:
  44. ;             NUMCHAR=INP_CNT()
  45. ;
  46. ; 4- SET_XOFF {CALL} enables or disables xoff control .
  47. ;    Example:
  48. ;             SOFF=.T. && if you want to turn xoff feature on
  49. ;             SOFF=.F. && to turn it off
  50. ;             CALL SET_XOFF WITH SOFF
  51. ;
  52. ; 5- GET_XOFF(),RECV_XOFF(),SENT_XOFF() {FUNCTION} return logical value
  53. ;    indicating state of control flags
  54. ;    Example:
  55. ;             GFLAG=GET_XOFF()
  56. ;
  57. ; 6- INIT_COMM,UNINIT_COM,INP_FLUSH {CALL} dont pass or return parameters
  58. ;    Example:
  59. ;             CALL INIT_COMM
  60. ;             CALL INP_FLUSH
  61. ;---------------------------------------------------------------------------
  62. ;
  63.  
  64.  
  65.  
  66. name COMM_IO
  67.  
  68. public  init_comm       ;initialize the comm port,
  69. public  uninit_com      ;remove initialization,
  70. public  set_xoff        ;enable/disable XON/XOFF,
  71. public  get_xoff        ;read XON/XOFF state,
  72. public  rcvd_xoff       ;returns true if XOFF rcvd,
  73. public  sent_xoff       ;true if XOFF sent,
  74. public  inp_cnt         ;returns count of rcv chars,
  75. public  inp_char        ;get char string from buffer,
  76. public  inp_flush       ;flush input buffer,
  77. public  outp_char       ;output a character string,
  78. ;
  79. extrn   _retc:far      ; return character string
  80. extrn   _retds:far     ; return date type from date string "YYYYMMDD"
  81. extrn   _retl:far      ; return logical true or false
  82. extrn   _retni:far     ; return word as numeric
  83. extrn   _retnl:far     ; return double word as numeric
  84. extrn   _retnd:far     ; return floating point as numeric
  85. ;
  86. extrn   _parc:far      ; pass character string
  87. extrn   _parni:far     ; pass integer numeric
  88. extrn   _parnl:far     ; pass integer long numeric
  89. extrn   _parnd:far     ; pass double numeric
  90. extrn   _parl:far      ; pass logical integer
  91. extrn   _pards:far     ; pass date string "yyyymmdd"
  92. ;
  93. extrn   _parinfo:far   ; UNDEF           0
  94.                        ; CHARACTER       1
  95.                        ; NUMERIC         2
  96.                        ; LOGICAL         4
  97.                        ; DATE            8
  98.                        ; ALIAS           16
  99.                        ; MPTR            32
  100.                        ; MEMO            65
  101.                        ; WORD            128
  102. _prog  segment byte public 'code'
  103. assume  cs:_prog
  104. ;
  105. ;
  106. FALSE   EQU     0
  107. TRUE    EQU     NOT FALSE
  108. BASE    EQU     03F8H   ;BASE FOR SERIAL BOARD COMM1
  109. LCR     EQU     BASE+3  ; Line control register
  110. IER     EQU     BASE+1  ; Interrup Enable Register
  111. MCR     EQU     BASE+4  ; modem control register
  112. EnblDRdy EQU    01H     ; enable 'data-ready' interrupt bit
  113. IntCtlr  EQU    21H     ; OCW 1 FOR 8259 CONTROLLER
  114. EnblIRQ4 EQU    0EFH    ; Enable COMMUNICATIONS (IRQ4) COMM1
  115. DATAPORT EQU    BASE    ; transmit/receive data port
  116. MaskIRQ4 EQU    10H     ; BIT TO DISABLE COMM INTERRUPT (IRQ4)
  117. MDMSTA  EQU     BASE+5  ; line status register
  118. MDMMSR  EQU     BASE+6  ; modem status register
  119. MDMBAD  EQU     BASE    ; lsb baud resgister
  120. MDMBD1  EQU     BASE+1  ; msb baud rate register
  121. MDMCD   EQU     80H     ; mask for carrier dectect
  122. SETBAU  EQU     80H     ; code for Divisor Latch Access Bit
  123. MDMTBE  EQU     20H     ; 8250 tbe flag
  124. MDMBRK  EQU     40H     ; command code for 8250 break
  125. LINMOD  EQU     03H     ; line mode=8 bit, no parity
  126. MDMMOD  EQU     0BH     ; modem mode = DTR and RTS HIGH
  127. STOP2   EQU     04H     ; BIT FOR TWO STOP BITS IF BAUD<300
  128. RS8259  EQU     20H     ; OCW 3 FOR 8259
  129. RSTINT  EQU     64H     ; SPECIFIC EOI FOR COMM INTERRUPT
  130. XOFF    EQU     13H     ; XOFF character
  131. XON     EQU     11H     ; XON character
  132. ;
  133.  ;       MISCELLANEOUS EQUATES
  134. ;
  135. CR      EQU     13
  136. LF      EQU     10
  137. DosCall EQU     33      ;INTERRUPT NUMBER FOR DOS CALL
  138. CNSTAT  EQU     11      ;FUNCTION NUMBER FOR CONSOLE STATUS
  139. CNIN    EQU     1       ;FUNCTION NUMBER FOR CONSOLE INPUT
  140. BUFSIZ  EQU     512     ;Max NUMBER OF CHARS
  141. SetIntVect  EQU 25H     ;SET INTERRUPT VECTOR FUNCTION NUMBER
  142.  
  143. ;
  144. ;       DUMP BUFFER, COUNT AND POINTER.
  145. ;
  146. CIRC_BUF  DB    BUFSIZ DUP(?)   ;ALLOW 512 MAXIMUM BUFFERED CHARACTERS
  147. BUF_TOP   EQU   $ - 1           ;KEEP TRACK OF THE TOP OF THE BUFFER
  148. OUT_BUF   DB    BUFSIZ DUP(?)   ;TEMP BUFF AREA FOR CALLING PROCEDURE
  149. CIRC_TOP  DW    BUF_TOP         ;
  150. CIRC_IN   DW    OFFSET CIRC_BUF ;POINTER TO LAST CHAR. PLACED IN BUFFER
  151. CIRC_CUR  DW    OFFSET CIRC_BUF ;POINTER TO NEXT CHAR. TO BE RETRIEVED FROM
  152.                                 ; BUFFER
  153. CIRC_CT   DW    0               ;COUNT OF CHARACTERS USED IN BUFFER
  154. SNT_XOFF  DB    FALSE           ;FLAG TO CHECK IF AN XOFF HAS BEEN SEND
  155. GOT_XOFF  DB    FALSE           ;FLAG TO CHECK IF AN XOFF HAS BEEN RECEIVED
  156. SEE_XOFF  DB    FALSE           ;FLAG TO SEE IF WE ARE INTERESTED IN XON/XOFF
  157. CIRC_OUT  DW    0               ;NUMBER OF CHARACTERS RETURNED TO CLIPPER
  158. INTR_CUR  DW    0               ;BUFFER FOR INP_CHAR
  159. INTR_CT   DW    0               ;BUFFER FOR INP_CHAR
  160. KILLSTR   DB    0               ;FLAG PASSED TO KILL BUFFER UPON READING
  161. ;
  162. ;
  163. ;
  164. ;set_xoff(flag)         Enable (flag = 1 ) or disable
  165. ;int flag;              (flag = 0 ) XON/ XOFF protocol
  166. ;                       for the character input stream.
  167. ;If enabled, an XOFF will be sent when  the buffer
  168. ;reaches 3/4 full. NOTE: an XON will not be sent auto-
  169. ;matically. Your program must do it when it sees
  170. ;the rcvd_xoff() flag,  and ready for more chars.
  171. ;
  172. set_xoff proc far
  173.         push    bp
  174.         mov     bp,sp
  175.         PUSH    DS                  ;SAVE DATA SEGMENT
  176.         lds     si,dword ptr [bp+6] ; get calling varible addr off stack
  177.         xor     ax,ax
  178.         lodsb                       ; load al with calling variable
  179.         push    cs
  180.         pop     ds                  ; move code seg addr to data seg reg.
  181.         cmp     al,0                ; check for logic 0
  182.         jnz     to_on               ; if not 0 set it true=-1
  183.         mov     see_xoff,FALSE
  184.         jmp     done1
  185. to_on:  mov     see_xoff,TRUE
  186. done1:  pop     ds
  187.         pop     bp
  188.         ret
  189. set_xoff endp
  190. ;
  191. ;flag=  get_xoff()      Returns the current setting
  192. ;                       of the XON/ XOFF flag set
  193. ;by set_xoff(), ab